package com.kusiri.kframework.metadata
{
	import com.kusiri.kframework.component.property.IKfComponentPropertyEditor;
	
	import mx.core.IFlexDisplayObject;
	
	public class KfComponentPropertyConfiguration
	{
		/**
		 *
		 */
		protected var _value : XML;

		/**
		 *
		 */
		protected var _name : String;
		
		/**
		 *
		 */
		protected var _componentConfiguration : KfComponentConfiguration;
		
		public function KfComponentPropertyConfiguration( componentConfiguration : KfComponentConfiguration, name : String, value : XML ) : void
		{
			_componentConfiguration = componentConfiguration;
			_name = name;
			_value = value;
		}
		
		public static function fromXml(componentConfiguration : KfComponentConfiguration, xml : XML) : KfComponentPropertyConfiguration
		{
			return new KfComponentPropertyConfiguration(componentConfiguration, xml.@name, xml.*[0]);
		}
		
		public function toXml() : XML
		{
			return <property name={name}>{value}</property>;
		}
		
		public function get name() : String
		{
			return _name;
		}
		
		public function get value() : XML
		{
			return _value;
		}
		
		public function newViewer() : IFlexDisplayObject
		{
			return _componentConfiguration.metadata.getPropertyMetadata(_name).newViewer(_componentConfiguration.applicationConfiguration,this);
		}
		
		public function newEditor() : IKfComponentPropertyEditor
		{
			return _componentConfiguration.metadata.getPropertyMetadata(_name).newEditor(_componentConfiguration.applicationConfiguration, this);
		}
		
	}
}